<?php 
require_once 'include.php';
$CartPros=getAllCartPro();
$total=0.00;
checkUserLogined();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>购物车</title>
<link type="text/css" rel="stylesheet" href="styles/reset.css">
<link type="text/css" rel="stylesheet" href="styles/main.css">
	<script src="js/addFavorite.js"></script>
	<script src="js/jquery-1.6.js" type="text/javascript"></script>
<!--[if IE 6]>
<script type="text/javascript" src="js/DD_belatedPNG_0.0.8a-min.js"></script>
<script type="text/javascript" src="js/ie6Fixpng.js"></script>
<![endif]-->
</head>

<body>
<div class="headerBar">
	<div class="topBar">
		<div class="comWidth">
			<div class="leftArea">
				<a href="#" onclick="AddFavorite(window.location,document.title)" class="collection" >收藏网站</a>
			</div>
			<div class="rightArea">
				欢迎来到松田淘淘乐！
				<?php if($_SESSION['loginFlag']):?>
				<span>欢迎您</span><?php echo $_SESSION['username'];?>
				<a href="doAction.php?act=userOut">[退出]</a>
				<?php else:?>
				<a href="login.php">[登录]</a><a href="reg.php">[免费注册]</a>
				<?php endif;?>
			</div>
		</div>
	</div>
	<div class="logoBar">
		<div class="comWidth">
			<div class="logo fl">
				<a href="index.php"><img src="images/logo_index.png" alt="松田淘淘乐"></a>
			</div>
			<div class="stepBox fr">
				<div class="step01"></div>
				<ul class="step_text">
					<li class="s01 active">我的购物车</li>
					<li class="s02">填写核对订单</li>
					<li class="s03">订单提交成功</li>
				</ul>
			</div>
		</div>
	</div>
</div>
<div class="shoppingCart comWidth">
	<div class="hr_25"></div>
	<div class="shopping_item">
		<h3 class="shopping_tit">购物车列表
			<a href="javascript:clearCart();" class="backCar">清空购物车</a>
			<a href="javascript:history.go(-1);" class="backCar">返回继续购物</a>
		</h3>
		<div class="shopping_cont pb_10">
			<div class="cart_inner">
				<div class="cart_head clearfix">
					<div class="cart_item t_name">商品名称</div>
					<div class="cart_item t_price_cart">单价</div>
					<div class="cart_item t_return_cart">返现</div>
					<div class="cart_item t_num_cart">数量</div>
					<div class="cart_item t_subtotal_cart">小计</div>
					<div class="cart_item t_operator_cart">操作</div>
				</div>
				<?php foreach($CartPros as $pros):?>
				<div class="cart_cont clearfix" id="div-<?php echo $pros['pid'] ?>">
					<div class="cart_item t_name">
						<div class="cart_shopInfo clearfix">
							<img src="image_350/<?php $proImgs=getProImgsById($pros['pid']);echo $proImgs[0]['albumPath'];?>" alt="">
							<div class="cart_shopInfo_cont">
								<p class="cart_link"><a href="#"><?php $proInfo=getProById($pros['pid']);echo $proInfo['pName']?></a></p>
								<p class="cart_info">微信支付微信支付微信支付微</p>
							</div>
						</div>
					</div>
					<div class="cart_item t_price_cart"><span id="p-<?php echo $pros['pid']?>"><?php echo $pros['price'] ?></span></div>
					<div class="cart_item t_return_cart" style="width:78px">无返现</div>
					<div class="cart_item t_num_cart" style="width:135px">
					<div class="des_number" >
						<a href="javascript:numDes(<?php echo $pros['pid'] ?>);"><div class="reduction">-</div></a>
							<div class="des_input">
								<input type="text" name="number" id="<?php echo $pros['pid'] ?>" value="<?php echo $pros['num'] ?>" onblur="changeNum(<?php echo $pros['pid'] ?>,this.value)">
							</div>
						<a href="javascript:numPlus(<?php echo $pros['pid'] ?>);"><div class="plus">+</div></a>
						</div>
					</div>
					<div class="cart_item t_subtotal_cart t_red">￥<span id="total-<?php echo $pros['pid'] ?>"><?php echo $subtotal=$pros['price']*$pros['num'];$total+=$subtotal; ?></span></div>
					<div class="cart_item t_operator_cart" ><a href="javascript:delPro(<?php echo $pros['pid'] ?>);">删除</a></div>
				</div>
				<?php endforeach;?>
				<script type="text/javascript">
					function numPlus(productid){
						num=document.getElementById(productid).value;
						num=parseInt(num);
						if(num<1000){
							document.getElementById(productid).value=num+1;
							changeNum(productid,document.getElementById(productid).value);
						}
							
					}
					function numDes(productid){
						num=document.getElementById(productid).value;
						num=parseInt(num);
						if(num>1){
							document.getElementById(productid).value=num-1;
							changeNum(productid,document.getElementById(productid).value);
						}
					}
					function changeNum(productid,num){
						var url="doAction.php?act=changeNum";
						var data={"productid":productid,"num":num};
						var success=function(response){
								if(response.errno==0){
									num=document.getElementById(productid).value;
									var price=(parseInt(num))*($("#p-"+productid).html());
									$("#total-"+productid).html(price);
									price=0;
									<?php  foreach($CartPros as $pros):?>
                                        num=document.getElementById(<?php echo $pros['pid']?>).value;
    									price+=(parseInt(num))*($("#p-"+<?php echo $pros['pid']?>).html());
									<?php endforeach;?>
									$("#totalAll").html("￥"+price);
								}else{
									alert("修改购物车失败");
								}
							}
						$.post(url,data,success,"json");
					}
					function delPro(productid){
						var url="doAction.php?act=deleteProduct";
						var data={"productid":productid};
						var success=function(response){
								if(response.errno==0){
									$("#div-"+productid).remove();
									
								}else{
									alert("删除失败");
								}
							}
						$.get(url,data,success,"json");
					}
					function clearCart(){
						var url="doAction.php?act=clearCart";
						var success=function(response){
								if(response.errno==0){
									$(".cart_cont").remove();
									$("#totalAll").html("￥0");
								}else{
									alert("清空失败");
								}
							}
						$.get(url,success,"json");
					}
				</script>
				<div class="cart_message">
					若有问题请留言，若有问题请拨打客服热线66666
				</div>

			</div>
		</div>
	</div>
	<div class="hr_25"></div>
	<div class="shopping_item">
		<h3 class="shopping_tit">订单结算</h3>
		<div class="shopping_cont padding_shop clearfix">
			<div class="cart_count fr">
				<div class="cart_rmb">
					<i>总计：</i><span id="totalAll">￥<?php echo $total; ?></span>
				</div>
				<div class="cart_btnBox">
					<a href="settle.php"><input type="button"  class="cart_btn" value="去结算"></a>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="hr_25"></div>

<?php include('footer.php');?>
</body>
</html>

<?php
